home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / PRGMMING / PWORD_MC.ZIP / CHANGE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-04  |  2.5 KB  |  118 lines

  1. //Change password routine
  2. //Michael J. Campbell, 1994
  3.  
  4. #include <dos.h>
  5. #include <stdio.h>
  6. #include <graphics.h>
  7. #include <conio.h>
  8. #include <string.h>
  9. #include "keycodes.h"
  10.  
  11. // Outside functions/variables
  12. extern char text[30], password[30];
  13. extern void write_text(int,int,int,int,int,int,int);
  14. extern int ESC_pressed;
  15. extern void wait(void);
  16.  
  17.  
  18. void change(void)
  19.     {
  20.  
  21.     int tries = 0;
  22.     FILE *fp;
  23.  
  24.     char temp_pass[30];
  25.     strcpy(temp_pass,"");
  26.     strcpy(text,"");
  27.  
  28.     // Prompt user to change password
  29.     setfillstyle(SOLID_FILL,LIGHTGRAY);
  30.     bar(203,203,437,287);
  31.     setcolor(BLACK);
  32.     settextstyle(SMALL_FONT,HORIZ_DIR,4);
  33.     settextjustify(CENTER_TEXT,CENTER_TEXT);
  34.     outtextxy(320,210,"Press <ESC> to cancel");
  35.     settextjustify(RIGHT_TEXT,CENTER_TEXT);
  36.  
  37.     outtextxy(323,230," Enter OLD Password:");
  38.     outtextxy(323,245," Enter NEW Password:");
  39.     outtextxy(323,260,"Renter NEW Password:");
  40.  
  41.     // Get input loop
  42.     while(1)
  43.         {
  44.         // Clear input lines
  45.         bar(334,255,437,265);
  46.         bar(334,240,437,250);
  47.         bar(334,225,437,235);
  48.  
  49.         // Do some checking
  50.         if(ESC_pressed) break;
  51.         tries++;
  52.  
  53.         // Annoy user some more
  54.         if(tries > 2) { wait(); break; }
  55.  
  56.         // Get password
  57.         write_text(335,230,BLACK,BLACK,LIGHTGRAY,15,0);
  58.  
  59.         if(ESC_pressed) break;
  60.  
  61.         if(strcmp(text,password) == 0)
  62.             {
  63.             // Get new password
  64.             write_text(335,245,BLACK,BLACK,LIGHTGRAY,15,0);
  65.  
  66.             if(ESC_pressed) break;
  67.  
  68.             // Put new password in temp variable
  69.             strcpy(temp_pass,text);
  70.  
  71.             // Confirm new password loop
  72.             do
  73.                 {
  74.                 // Get new password again
  75.                 write_text(335,260,BLACK,BLACK,LIGHTGRAY,15,0);
  76.  
  77.                 if(ESC_pressed) break;
  78.  
  79.                 // Confirm new password matches
  80.                 if(strcmp(text,temp_pass) == 0)
  81.                     {
  82.                     setcolor(BLACK);
  83.                     settextjustify(CENTER_TEXT,CENTER_TEXT);
  84.                     outtextxy(320,280,"Press <ENTER> To Accept");
  85.  
  86.                     // Change the password
  87.                     if(getch() == ENTER)
  88.                         {
  89.                         fp = fopen("c:\\allow.use","w+");
  90.                         fprintf(fp,temp_pass);
  91.                         fclose(fp);
  92.                         ESC_pressed = 1;
  93.                         break;
  94.                         }
  95.                     else // Cancel change
  96.                         {
  97.                         ESC_pressed = 1;
  98.                         break;
  99.                         } // End if
  100.  
  101.                     }
  102.                 else // Failure of new password confirmation
  103.                     {
  104.                     bar(334,255,437,265);
  105.                     setcolor(BLACK);
  106.                     outtextxy(335,260,"INCORRECT");
  107.                     delay(3000);
  108.                     bar(334,255,437,265);
  109.                     rewind(fp);
  110.                     } // End if
  111.  
  112.                 } while(strcmp(text,temp_pass) != 0); // End do
  113.  
  114.             } // End if
  115.  
  116.         } // End while
  117.  
  118.     } // End function